﻿#ifndef DATASOURCE_H
#define DATASOURCE_H

#include "datasource.h"
#include "TileKey.h"
#include "TileOption.h"
#include <osg/Image>
#include <osg/Shape>
#include <QString>

namespace rxtiler {

    class DataSourceMetaData
    {
    public :
        TileOption tileOption;
        Extent dataExtent;
        int level0;
        int level1;
    };

    class DataSource
    {
    public:
        DataSource();

        virtual ~DataSource();

        virtual bool open();

        virtual bool close();
        //获取数据源空间范围
        virtual Extent getExtent();
        //计算该数据在option金字塔结构下的层级范围
        virtual bool computerLevels(TileOption* option,int* min,int* max);
        //获取瓦片对应的影像
        virtual osg::Image* getImage(TileKey& key,Extent& extent);
         virtual osg::Image* getImages(TileKey& key,Extent& extent);
        virtual osg::HeightField* getDEM(TileKey &key,Extent& extent);
        //保存该瓦片的影像
        virtual bool saveImage(TileKey& key,osg::Image* img);
        virtual bool saveDEM(TileKey &key, osg::HeightField *dem);

        void setPath(QString p);
        inline void setTileSize(int i){_tileSize = i;}
        inline int getTileSize(){return _tileSize;}
        inline void setFileExt(QString ext){_fileext = ext;}
        inline QString getFileExt(){return _fileext;}
        //void setMetaData(DataSourceMetaData* md);
        DataSourceMetaData *getOrCreateMetaData();
        virtual bool saveMetaData();
//        DataSourceMetaData* _metaData{0};
    protected:
        QString _fileext;
        QString _path;
        int _tileSize;
        DataSourceMetaData* _metaData{0};
    };

}



#endif // DATASOURCE_H
